
* Appendix S - Stability of party positions following election day

clear all
cd "${data}"	
use "data1.dta", clear


*recode CHES_year (1999=2000) (2002=2003) (2006=2007) (2010=2011) (2019=2020)

drop if IMD5012_==.
drop if CHES_leftright==.
drop if respondent==.

/*

CHES 2019 administered in winter 2020.
CHES 2014 administered in fall 2014
CHES 2010 administered in spring 2011 
CHES 2006 administered in summer 2007
CHES 2002 administered in spring 2003
CHES 1999 administered in spring/summer 2000

SWE_2002 elections in september 2002, CHES in spring 2003
SWE_2006 elections in september 2006, CHES in summer 2007
NLD_2002 elections in may 2002, CHES in spring 2003
NLD_2006 elections in november 2006, CHES in summer 2007
DEU_2002 elections in september 2002, CHES in spring 2003 
DEU_2013 elections in september 2013, CHES in fall 2014 
AUT_2013 elections in september 2013, CHES in fall 2014
IRL_2002 elections in may 2002, CHES in spring 2003

*/

keep if  election == "SWE_2002" | election == "SWE_2006" | election == "NLD_2002" | election == "NLD_2006" | election == "DEU_2002" | election == "DEU_2013" | election == "AUT_2013" | election == "IRL_2002" 


*replace CHES_leftright=round(CHES_leftright, 1)

gen positionchange = abs(CHES_leftright - IMD5012_)

keep election IMD5012_ CHES_leftright IMD5000_ ingovernment IMD5001_ positionchange
duplicates drop

hist positionchange, percent color(gs7%50) ytitle(percent, size(small)) xtitle(position change / difference between CSES and CHES experts perceptions, size(small))
	graph save "${figures}/figureS1.gph", replace
	graph export "${figures}/figureS1.png", replace

	
hist positionchange, percent color(gs7%50) ytitle(percent, size(small)) xtitle(position change / difference between CSES and CHES experts perceptions, size(small)) by(ingovernment)
	graph save "${figures}/figureS2.gph", replace
	graph export "${figures}/figureS2.png", replace

	
	


clear all
cd "${data}"	
use "data1.dta", clear

keep if  election == "SWE_2002" | election == "SWE_2006" | election == "NLD_2002" | election == "NLD_2006" | election == "DEU_2002" | election == "DEU_2013" | election == "AUT_2013" | election == "IRL_2002" 

drop if IMD5012_==.
drop if CHES_leftright==.
drop if respondent==.

*replace CHES_leftright=round(CHES_leftright, 1)

gen positionchange = abs(CHES_leftright - IMD5012_)

gen changed = .
replace changed = 1 if positionchange>0.99
replace changed = 0 if positionchange<1

eststo m1: mixed IMD3007_ c.daysafter##c.IMD5012_##i.changed ||  election_: || respondent: IMD5012_
margins, dydx(IMD5012_) at(daysafter==(0(30)210)) over(changed)
marginsplot 

 graph save "${figures}/figureS3.gph", replace
 graph export "${figures}/figureS3.png", replace
 
 
cd "${tables}"
esttab m1 using tableS1.tex, replace ///
b(3) se(3) nogap transform(ln*: exp(2*@) 2*exp(2*@)) ///
label mlabels ("Model 1")
	